<?php
class ModelMartCrmRegisterCustomer extends Model {
    
//    public function Good($data = array()) { 
//		echo $data['filter_date_start'].$data['filter_date_end'];
//	}
	public function getRegisterCustomer($data = array()) { 
		$sql = "SELECT crm_card.id, MONTH( crm_card.date_entered ) AS name, COUNT( * ) AS count
FROM crm_card
WHERE YEAR( crm_card.date_entered ) ='";
                if (!empty($data['filter_group'])) {
                                $sql .= $this->db->escape($data['filter_group']) . "'";

                        }
                        $sql .= "GROUP BY MONTH( crm_card.date_entered )";
		
                        
		$query = $this->db->query($sql);
               
		return $query->rows;
               // echo $query;
	}

	public function getTotalCustomersOnline($data = array()) {
		$sql = "SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "customer_online` co LEFT JOIN " . DB_PREFIX . "customer c ON (co.customer_id = c.customer_id)";
		
		$implode = array();
		
		if (isset($data['filter_ip']) && !is_null($data['filter_ip'])) {
			$implode[] = "co.ip LIKE '" . $this->db->escape($data['filter_ip']) . "'";
		}
		
		if (isset($data['filter_customer']) && !is_null($data['filter_customer'])) {
			$implode[] = "co.customer_id > 0 AND CONCAT(c.firstname, ' ', c.lastname) LIKE '" . $this->db->escape($data['filter_customer']) . "'";
		}
		
		if ($implode) {
			$sql .= " WHERE " . implode(" AND ", $implode);
		}
				
		$query = $this->db->query($sql);

		return $query->row['total'];
	}
}
?>